package com.woniu.gateway.config;

import com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayFlowRule;
import com.alibaba.csp.sentinel.datasource.Converter;
import com.alibaba.fastjson2.JSON;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

@Configuration
public class SentinelGatewayConverterConfiguration {


    @Bean("sentinel-json-gw-flow-converter")
    public Converter<String, Set<GatewayFlowRule>> gatewayFlowRuleConverter() {
        return source -> {
            List<GatewayFlowRule> list = JSON.parseArray(source, GatewayFlowRule.class);
            return new HashSet<>(list);
        };
    }
}